package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zarj {
   ArrayList a;
   private com.aspose.cells.a.f.zj c = null;
   private Workbook d = null;
   zapt b;
   private zcfx e;

   public zarj(Workbook var1) {
      var1.getWorksheets().o();
      this.d = var1;
      this.b = new zapt(this.d);
      this.a = new ArrayList();
   }

   void a(com.aspose.cells.b.a.d.zm var1) throws Exception {
      this.c = new com.aspose.cells.a.f.zj(var1);
      this.c.b(2);
      this.c.d(0);
      this.e();
      this.b.b();
      zaqj var2 = new zaqj("application/vnd.oasis.opendocument.spreadsheet", "/");
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var2);
      this.b();
      zarh var3 = new zarh(this.b);
      var3.a(this.a, this.c);
      zaqx var4 = new zaqx(this.b);
      var4.a(this.a, this.c);
      this.d();
      this.a();
      this.c();
      this.c.f_();
      this.b.a();
   }

   void a() throws Exception {
      this.e = a("meta.xml", this.c);
      zaqj var1 = new zaqj("text/xml", "meta.xml");
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
      zaqo var2 = new zaqo(this.b);
      var2.a(this.e);
      this.e.e();
   }

   void b() throws Exception {
      this.e = a("content.xml", this.c);
      zaqj var1 = new zaqj("text/xml", "content.xml");
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
      this.e.c();
      this.e.b("office:document-content");
      this.e.a("xmlns", "office", (String)null, "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
      this.e.a("xmlns", "style", (String)null, "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
      this.e.a("xmlns", "text", (String)null, "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
      this.e.a("xmlns", "table", (String)null, "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
      this.e.a("xmlns", "draw", (String)null, "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
      this.e.a("xmlns", "fo", (String)null, "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
      this.e.a("xmlns", "xlink", (String)null, "http://www.w3.org/1999/xlink");
      this.e.a("xmlns", "dc", (String)null, "http://purl.org/dc/elements/1.1/");
      this.e.a("xmlns", "meta", (String)null, "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
      this.e.a("xmlns", "number", (String)null, "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0");
      this.e.a("xmlns", "svg", (String)null, "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
      this.e.a("xmlns", "chart", (String)null, "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
      this.e.a("xmlns", "dr3d", (String)null, "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0");
      this.e.a("xmlns", "math", (String)null, "http://www.w3.org/1998/Math/MathML");
      this.e.a("xmlns", "form", (String)null, "urn:oasis:names:tc:opendocument:xmlns:form:1.0");
      this.e.a("xmlns", "script", (String)null, "urn:oasis:names:tc:opendocument:xmlns:script:1.0");
      this.e.a("xmlns", "ooo", (String)null, "http://openoffice.org/2004/office");
      this.e.a("xmlns", "ooow", (String)null, "http://openoffice.org/2004/writer");
      this.e.a("xmlns", "oooc", (String)null, "http://openoffice.org/2004/calc");
      if (this.b.n) {
         this.e.a("xmlns", "of", (String)null, "urn:oasis:names:tc:opendocument:xmlns:of:1.2");
      }

      this.e.a("xmlns", "dom", (String)null, "http://www.w3.org/2001/xml-events");
      this.e.a("xmlns", "xforms", (String)null, "http://www.w3.org/2002/xforms");
      this.e.a("xmlns", "xsd", (String)null, "http://www.w3.org/2001/XMLSchema");
      this.e.a("xmlns", "xsi", (String)null, "http://www.w3.org/2001/XMLSchema-instance");
      this.e.a("office", "version", (String)null, this.b.m);
      zarf var2 = new zarf(this.b);
      var2.a(this.e);
      this.f();
      this.e.b();
      this.e.d();
      this.e.e();
   }

   private void f() throws Exception {
      this.e.b("office:body");
      this.g();
      this.e.b();
   }

   private void g() throws Exception {
      this.e.b("office:spreadsheet");

      for(int var1 = 0; var1 < this.b.g.size(); ++var1) {
         this.d.l();
         zarl var2 = new zarl((zapu)this.b.g.get(var1));
         var2.a(this.e);
      }

      this.h();
      this.e.b();
   }

   private void h() throws Exception {
      NameCollection var1 = this.d.getWorksheets().getNames();
      if (var1.getCount() != 0) {
         this.e.b("table:named-expressions");

         for(int var2 = 0; var2 < var1.getCount(); ++var2) {
            Name var3 = var1.get(var2);
            this.e.b("table:named-expression");
            String var4 = var3.getText();
            switch(var3.p()) {
            case 6:
               var4 = "Excel_BuiltIn_Print_Area_" + var3.getSheetIndex();
               break;
            case 7:
               var4 = "Excel_BuiltIn_Print_Titles_" + var3.getSheetIndex();
               break;
            case 13:
               var4 = "Excel_BuiltIn__FilterDatabase_" + var3.getSheetIndex();
            }

            this.e.a("table", "name", (String)null, var4);
            int var5 = var3.getSheetIndex() - 1;
            if (var5 < 0) {
               var5 = var3.o();
               if (var5 < 0 || var5 >= this.d.getWorksheets().getCount()) {
                  var5 = 0;
               }
            }

            this.e.a("table", "base-cell-address", (String)null, "$" + this.d.getWorksheets().get(var5).getName() + ".$A$1");
            String var6 = zaqh.a(this.d.getWorksheets(), var3);
            if (var6 != null && !"".equals(var6) && var6.charAt(0) == '=') {
               var6 = var6.substring(1);
            }

            this.e.a("table", "expression", (String)null, var6);
            this.e.b();
         }

         this.e.b();
      }
   }

   void c() throws Exception {
      zcfx var1 = a("META-INF/manifest.xml", this.c);
      var1.c();
      var1.b("manifest:manifest");
      var1.a("xmlns", "manifest", (String)null, "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0");

      for(int var2 = 0; var2 < this.a.size(); ++var2) {
         zaqj var3 = (zaqj)this.a.get(var2);
         var1.b("manifest:file-entry");
         var1.a("manifest", "media-type", (String)null, var3.a());
         var1.a("manifest", "full-path", (String)null, var3.b());
         var1.b();
      }

      var1.b();
      var1.d();
      var1.a((int)1);
      var1.e();
   }

   void d() throws Exception {
      HashMap var1 = new HashMap();
      if (this.b.a.getWorksheets() != null && this.b.a.getWorksheets().getCount() > 0) {
         Iterator var2 = this.b.a.getWorksheets().iterator();

         while(true) {
            Worksheet var3;
            do {
               do {
                  if (!var2.hasNext()) {
                     return;
                  }

                  var3 = (Worksheet)var2.next();
               } while(var3.getShapes() == null);
            } while(var3.getShapes().getCount() <= 0);

            Iterator var4 = var3.getShapes().iterator();

            while(var4.hasNext()) {
               Shape var5 = (Shape)var4.next();
               int var6 = var5.getMsoDrawingType();
               switch(var6) {
               case 5:
                  String var11 = zaqh.a((ChartShape)var5);
                  String var12 = "Object " + var11;
                  com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("text/xml", var12 + "/content.xml")));
                  com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("text/xml", var12 + "/styles.xml")));
                  com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("text/xml", var12 + "/meta.xml")));
                  com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("application/vnd.oasis.opendocument.chart", var12)));
                  zapm var13 = new zapm(this.b, this.c, (ChartShape)var5, var11);
                  var13.a();
                  break;
               case 6:
                  MsoFillFormat var7 = var5.getFillFormat();
                  if (var7.getImageData() != null) {
                     this.b(var7.b(), var7.getImageData());
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("image/jpeg", var7.b())));
                  }
                  break;
               case 8:
                  Picture var8 = (Picture)var5;
                  if (var8.getData() != null && var1.get(var8.b()) == null) {
                     String var14 = "Pictures/" + var8.b() + zase.a(var8.getImageFormat());
                     this.b(var14, var8.getData());
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("image/jpeg", var14)));
                     var1.put(var8.b(), true);
                  }
                  break;
               case 24:
                  OleObject var9 = (OleObject)var5;
                  String var10 = "MSO_OLE_OBJ" + com.aspose.cells.a.c.zp.e(var9.s());
                  if (!this.a(var10, var9.getObjectData())) {
                     this.b(var10, var9.getObjectData());
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("application/vnd.sun.star.oleobject", var10)));
                  } else {
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("application/vnd.oasis.opendocument.text", var10)));
                  }

                  if (var1.get(var9.e()) == null) {
                     this.b("ObjectReplacements/Object " + var9.e(), var9.getImageData());
                     com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("application/x-openoffice-wmf;windows_formatname=&quot;Image WMF&quot;", "ObjectReplacements/Object " + var9.e())));
                     var1.put(var9.e(), true);
                  }
               }
            }
         }
      }
   }

   private boolean a(String var1, byte[] var2) throws Exception {
      if (var2 == null) {
         return false;
      } else {
         com.aspose.cells.b.a.d.zh var3 = new com.aspose.cells.b.a.d.zh(var2);
         if (!zakq.a((com.aspose.cells.b.a.d.zm)var3)) {
            return false;
         } else {
            com.aspose.cells.a.f.zi var4 = com.aspose.cells.a.f.zi.a((com.aspose.cells.b.a.d.zm)var3);
            Iterator var5 = var4.iterator();

            while(var5.hasNext()) {
               com.aspose.cells.a.f.zh var6 = (com.aspose.cells.a.f.zh)var5.next();
               if (!var6.c() && !"META-INF/manifest.xml".equals(var6.b())) {
                  com.aspose.cells.b.a.d.zm var7 = var4.a(var6);
                  byte[] var8 = new byte[(int)var6.a()];
                  var7.a(var8, 0, (int)var6.a());
                  var7.a();
                  com.aspose.cells.a.f.zh var9 = this.c.a(var1 + "/" + var6.b());
                  var9.a(DateTime.getNow());
                  this.c.a(var9);
                  this.c.b(var8, 0, var8.length);
                  this.c.b();
                  com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new zaqj("text/xml", var1 + "/" + var6.b())));
               }
            }

            var3.a();
            var4.b();
            return true;
         }
      }
   }

   private void b(String var1, byte[] var2) throws Exception {
      if (var2 != null) {
         com.aspose.cells.a.f.zh var3 = this.c.a(var1);
         var3.a(DateTime.getNow());
         this.c.a(var3);
         this.c.b(var2, 0, var2.length);
         this.c.b();
      }
   }

   static zcfx a(String var0, com.aspose.cells.a.f.zj var1) throws Exception {
      com.aspose.cells.a.f.zh var2 = var1.a(var0);
      var2.a(DateTime.getNow());
      var1.a(var2);
      zcfx var3 = new zcfx(var1, Encoding.getUTF8());
      return var3;
   }

   void e() throws Exception {
      if (this.d.n().size() > 0) {
         com.aspose.cells.b.a.a.zc var1 = com.aspose.cells.b.a.a.zf.a(this.d.n());

         while(var1.c()) {
            byte[] var2 = (byte[])((byte[])var1.b());
            com.aspose.cells.a.f.zh var3 = this.c.a((String)var1.a());
            var3.a(DateTime.getNow());
            this.c.b(var2, 0, var2.length);
            zaqj var4 = new zaqj("text/xml", (String)var1.a());
            com.aspose.cells.b.a.a.ze.a(this.a, (Object)var4);
         }
      }

   }
}
